package com.tiantian.quanminxiu.adapter;

import android.app.Activity;
import android.view.View;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.tiantian.quanminxiu.R;
import com.tiantian.quanminxiu.model.RoomInfo;
import com.tiantian.quanminxiu.utils.APPUtils;

import java.util.ArrayList;

/**
 * Created by admin on 2016/1/14.
 */
public class SearchListAdapter extends BaseMultiItemQuickAdapter<RoomInfo>
{
    private Activity activity;

    public SearchListAdapter(Activity activity) {
        super(new ArrayList<RoomInfo>());
        this.activity = activity;
        addItemType(RoomInfo.HOT, R.layout.fragment_search_itemhot);
        addItemType(RoomInfo.COMMON,R.layout.fragment_search_itemresult);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, RoomInfo roomInfo) {
        switch (baseViewHolder.getItemViewType()) {
            case RoomInfo.HOT:
                baseViewHolder.setText(R.id.txtSearchTitle,roomInfo.getAnchorName())
                        .setTag(R.id.vMain,roomInfo.getRoomId());
                break;
            case RoomInfo.COMMON:
                baseViewHolder.setText(R.id.txtAnchorName, roomInfo.getAnchorName())
                        .setText(R.id.txtHotValue,roomInfo.getHeat()+"")
                        .setVisible(R.id.txtLiveStatu,roomInfo.getIsPlaying()==1?true:false)
                        .setTag(R.id.vMain,roomInfo.getRoomId())
                        .setImageResource(R.id.imgLevel, APPUtils.getAnchorLevelPic(activity,roomInfo.getAnchorLevel()));

                baseViewHolder.getView(R.id.imgAnchorAvatar).post(new Runnable() {
                    @Override
                    public void run() {
                        APPUtils.displayImage(APPUtils.createUserAvatar(roomInfo.getRoomId()), (ImageView) baseViewHolder.getView(R.id.imgAnchorAvatar), activity.getBaseContext(), baseViewHolder.getView(R.id.imgAnchorAvatar).getHeight() / 2);
                    }
                });
                break;
        }
        baseViewHolder.getView(R.id.vMain).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                APPUtils.PhoneLook_To(activity, (int) v.getTag());
            }
        });
    }
}
